package com.seeqool.v1.datamodel;

import java.util.Arrays;
import java.util.Vector;

public class SQLStrings extends SQLValues {
	
	private Vector<String> entries;
	private int[] values;
	
	public SQLStrings(int rowCount) {
		values = new int[rowCount];
		entries = new Vector<String>();
		entries.add(null);
	}
	
	public void set(int index, String value) {
		int pos = entries.indexOf(value);
		if (pos<0) {
			pos = entries.size();
			entries.add(value);
		}
		values[index] = pos;		
	}
	
	public String get(int index) {
		if ((index<0) || (index>=values.length)) return null;
		return entries.get(values[index]);
	}
	
	public String[] getUnique() {
		String[] result = new String[entries.size()];
		entries.copyInto(result);
		Arrays.sort(result);
		Arrays.binarySearch(result, "Hello");
		return result;
	}
	
	public void doubleSize() {
		int[] newvals = new int[values.length*2];
		System.arraycopy(values, 0, newvals, 0, values.length);
		values = newvals;
	}

	public void setSize(int rowCount) {
		int[] newvals = new int[rowCount];
		System.arraycopy(values, 0, newvals, 0, rowCount);
		values = newvals;
	}
}
